<!DOCTYPE html>
<html>
  <!-- Html Head Tag-->
  <head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="Rms">
  <!-- Open Graph Data -->
  <meta property="og:title" content="Linux安装tomcat"/>
  <meta property="og:description" content="" />
  <meta property="og:site_name" content="帅的一逼"/>
  <meta property="og:type" content="article" />
  <meta property="og:image" content="http://shsa.gitee.io"/>
  
    <link rel="alternate" href="/atom.xml" title="帅的一逼" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  

  <!-- Site Title -->
  <title>帅的一逼</title>

  <!-- Bootstrap CSS -->
  
<link rel="stylesheet" href="/myblog/css/bootstrap.min.css">

  <!-- Custom CSS -->
  
  
<link rel="stylesheet" href="/myblog/css/style.light.css">


  <!-- Google Analytics -->
  

<meta name="generator" content="Hexo 4.2.1"></head>

  <body>
    <!-- Page Header -->


<header class="site-header header-background" style="background-image: url(/myblog//img/i.jpg)">
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <div class="page-title with-background-image">
          <p class="title">Linux安装tomcat</p>
          <p class="subtitle"></p>
        </div>
        <div class="site-menu with-background-image">
          <ul>
            
              <li>
                <a href="/myblog/">
                  
                  Home
                  
                </a>
              </li>
            
              <li>
                <a href="/myblog/archives">
                  
                  Archives
                  
                </a>
              </li>
            
              <li>
                <a href="/myblog/about">
                  
                  About
                  
                </a>
              </li>
            
          </ul>
        </div>
      </div>
    </div>
  </div>
</header>

<article>
  <div class="container typo">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <div class="post-info text-muted">
          
            <!-- Author -->
            <span class="author info">By Rms</span>
          
          <!-- Date -->
          <span class="date-time info">On
            <span class="date">2020-07-16</span>
            <span class="time">21:53:53</span>
          </span>
          
        </div>
        <!-- Tags -->
        
        <!-- Post Main Content -->
        <div class="post-content">
          <h1 id="1-下载tomcat"><a href="#1-下载tomcat" class="headerlink" title="1.下载tomcat"></a>1.下载tomcat</h1><p>在apache下载你需要的tomcat版本</p>
<p>下载地址:<a href="https://tomcat.apache.org/download-90.cgi" target="_blank" rel="noopener">https://tomcat.apache.org/download-90.cgi</a></p>
<p>注意选择Core下面的文件</p>
<img src="https://pic.baixiongz.com/2020/07/16/d04be85e54aa4.png" alt="image.png" style="zoom:50%;" />



<p>使用浏览器复制下载链接</p>
<img src="https://pic.baixiongz.com/2020/07/16/9e6100b9a43ef.png" alt="image.png" style="zoom: 67%;" />

<p>使用wget命令进行下载,下载前记得先cd到/usr/local路径</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;usr&#x2F;local</span><br><span class="line">wget https:&#x2F;&#x2F;downloads.apache.org&#x2F;tomcat&#x2F;tomcat-9&#x2F;v9.0.37&#x2F;bin&#x2F;apache-tomcat-9.0.37.tar.gz</span><br></pre></td></tr></table></figure>

<p>下载完之后使用ls查看下载的文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls</span><br></pre></td></tr></table></figure>

<p>使用tar命令解压</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar zxvf apache-tomcat-9.0.37.tar.gz</span><br></pre></td></tr></table></figure>

<p>ls查看解压后的文件</p>
<p>使用mv命令重命名为tomcat</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ls</span><br><span class="line">mv apache-tomcat-9.0.37 tomcat</span><br></pre></td></tr></table></figure>

<h1 id="2-配置环境"><a href="#2-配置环境" class="headerlink" title="2.配置环境"></a>2.配置环境</h1><p>然后是配置环境</p>
<p>使用vim /etc/profile编辑profile文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vim &#x2F;etc&#x2F;profile</span><br><span class="line">&#x2F;&#x2F;部分linux没有安装vim命令，使用vi命名一样</span><br><span class="line">vi &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure>

<p>在profile文件末尾添加如下代码(按i进入编辑模式)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">CATALINA_HOME&#x3D;&#x2F;usr&#x2F;local&#x2F;tomcat</span><br><span class="line">CATALINA_BASE&#x3D;&#x2F;usr&#x2F;local&#x2F;tomcat</span><br><span class="line">PATH&#x3D;$PATH:$CATALINA_BASE&#x2F;bin</span><br><span class="line">export PATH CATALINA_BASE</span><br></pre></td></tr></table></figure>

<p>然后esc :wq保存</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:wq</span><br></pre></td></tr></table></figure>

<p>使用source /etc/profile使配置文件生效</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">source &#x2F;etc&#x2F;profile</span><br></pre></td></tr></table></figure>

<p>然后跳转到tomcat的安装目录的bin目录下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd &#x2F;usr&#x2F;local&#x2F;tomcat&#x2F;bin</span><br></pre></td></tr></table></figure>

<p>使用命令./startup.sh运行tomcat</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;startup.sh</span><br></pre></td></tr></table></figure>

<p>出现如下提示说明运行成功</p>
<img src="https://pic.baixiongz.com/2020/07/16/7f95929b5e7b6.png" alt="image.png" style="zoom: 80%;" />

<h1 id="3-测试"><a href="#3-测试" class="headerlink" title="3.测试"></a>3.测试</h1><h2 id="1-linux本地连接tomcat"><a href="#1-linux本地连接tomcat" class="headerlink" title="1.linux本地连接tomcat"></a>1.linux本地连接tomcat</h2><p>如果linux有可视化界面则在linux上面的浏览器输入</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">localhost:8080</span><br></pre></td></tr></table></figure>

<p>如果出现tomcat主页说明安装成功</p>
<p>如果没有可视化界面则使用下面命令测试是否安装成功</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -i localhost:8080</span><br></pre></td></tr></table></figure>

<p>如果返回html代码则说明安装成功</p>
<h2 id="2-远程连接tomcat"><a href="#2-远程连接tomcat" class="headerlink" title="2.远程连接tomcat"></a>2.远程连接tomcat</h2><p>打开浏览器，在地址栏输入 linux服务器ip地址:8080查看</p>
<p>查看ip命令</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ifconfig</span><br><span class="line">&#x2F;&#x2F;或者</span><br><span class="line">ip addr</span><br></pre></td></tr></table></figure>

<p>如果出现tomcat主页说明安装成功，如果访问不到则需要开放防火墙(阿里云需要开放安全组)</p>
<p>CentOS7.0以上默认使用firewall防火墙</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 查询端口是否开放</span><br><span class="line">firewall-cmd --query-port&#x3D;8080&#x2F;tcp</span><br><span class="line">&#x2F;&#x2F; 开放3306端口</span><br><span class="line">firewall-cmd --permanent --add-port&#x3D;8080&#x2F;tcp</span><br><span class="line">&#x2F;&#x2F; 重启防火墙(修改配置后要重启防火墙)</span><br><span class="line">firewall-cmd --reload</span><br></pre></td></tr></table></figure>

<p>CentOS7.0以下使用iptables防火墙</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 开启8080端口</span><br><span class="line">vim &#x2F;etc&#x2F;sysconfig&#x2F;iptables</span><br><span class="line">&#x2F;&#x2F; 加入如下代码(按i进入编辑模式)</span><br><span class="line">-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT</span><br><span class="line">&#x2F;&#x2F; 保存退出后重启防火墙 (按ESC输入:wq按ENTER保存退出)</span><br><span class="line">service iptables restart</span><br></pre></td></tr></table></figure>

<p><a href="javascript:void(0);">
  </a></p>

        </div>
      </div>
    </div>
  </div>
</article>



    <!-- Footer -->
<footer>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <p class="copyright text-muted">
          Theme By <a target="_blank" href="https://github.com/levblanc">Levblanc.</a>
          Inspired By <a target="_blank" href="https://github.com/klugjo/hexo-theme-clean-blog">Clean Blog.</a>
        <p class="copyright text-muted">
          Powered By <a target="_blank" href="https://hexo.io/">Hexo.</a>
        </p>
      </div>
    </div>
  </div>
</footer>


    <!-- After Footer Scripts -->

<script src="/myblog/js/highlight.pack.js"></script>

<script>
  document.addEventListener("DOMContentLoaded", function(event) {
    var codeBlocks = Array.prototype.slice.call(document.getElementsByTagName('pre'))
    codeBlocks.forEach(function(block, index) {
      hljs.highlightBlock(block);
    });
  });
</script>

  </body>
</html>

